/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-10-12 16:01:44
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-12-02 16:23:11
 */
// var name = "dev"; //本地
var name = "pre"; //测试
// var name = "pro"; //正式
const Global = require(`./env/${name}.js`);

const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const chalk = require("chalk");

module.exports = {
    productionSourceMap: false,
    configureWebpack: {
        devtool: "source-map"
    },
    chainWebpack: config => {
        config.plugin("progress-bar-webpack-plugin").use(ProgressBarPlugin, [
            {
                format:
                    " build [:bar] " +
                    chalk.green.bold(":percent") +
                    " (:elapsed seconds)",
                clear: false
            }
        ]);
        if (process.env.NODE_ENV !== "development") {
            // 查看打包文件体积大小
            config
                .plugin("webpack-bundle-analyzer")
                .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
        }
    },
    devServer: {
        // 设置代理
        proxy: {
            "/location_url": {
                target: Global.location_url, // 域名
                ws: true, // 是否启用websockets
                changeOrigin: true, //开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
                pathRewrite: {
                    "^/location_url": "/"
                }
            },
            "/lessonUrl": {
                target: Global.lessonUrl,
                ws: true,
                changeOrigin: true,
                pathRewrite: {
                    "^/lessonUrl": "/"
                }
            },
            "/semesterUrl": {
                target: Global.semesterUrl,
                ws: true,
                changeOrigin: true,
                pathRewrite: {
                    "^/semesterUrl": "/"
                }
            }
        }
    }
};
